// topicDetail.js
import { requestApi } from '../../../api'
import { constants } from '../../../sdk/constants.js'
import { Uuid } from '../../../sdk/uuid.js'
import tool from "../../../utils/tool.js";
import { formatImage } from '../../../utils/formatImage'
import { formatPrice } from '../../../utils/util'
import { dateFormat } from '../../../utils/dateFormat'
import { logUpload } from '../../../utils/logUpload'
let WxParse = require('../../../utils/wxParse/wxParse.js')

const app = getApp()

Page({
  data: {
    channel: '',
    start: 1,
    count: 20,
    tid: '',
    uid: '',
    topicData: [],
    shareTitle: '',
    shareDetail: '',
    shareImage: '',
    recommendData: [],
    noData: false,
    topicUrl: '',
    supportLaunchApp: false, // 是否支持打开APP
    parseList: [],
    shareCampaign: '',
    shareUtmTerm: '',
    shareUtmContent: '',
    shareUtmSearchKeyword: '',
    shareUtmTrafficSourceType: '',
    // 曝光埋点相关
    scrollActionY: 0,
    scrollFlag: [],
    entrenceTime: '',
    navList: [],
    stickyTop: 0,
    isStickyFloor: false,
    isShowFloorAll: false,
    activeFloor: '',
    menuWidth: 0,
    menuScrollLeft: 0,
    isMenuScroll: true,
    allHeight: '',
    dialogHidden: true,
    currentLiveInfo: {},
    toastMsg: '',
    toastHidden: true,
    protocol: '',
  },

  /**
   * 页面初始化
   */
  onLoad: function (options) {
    wx.showLoading({
      title: '加载中',
    })
    console.log(11111)
    let channel = ''
    let tid = ''
    let scene = ''
    let paramArr = []
    let utm_source = ''
    let utm_share = ''
    let utm_medium = ''
    let utm_term = ''
    let utm_content = ''
    let utm_campaign = ''
    let utm_search_keyword = ''
    let utm_traffic_source_type = ''

    // app端二维码分享
    if (options.scene && options.scene.length) {
      scene = decodeURIComponent(options.scene)
      paramArr = scene.split(',')

      if (paramArr[1] == 'sl') {
        app.shortUrlToLong(paramArr[0], (res) => {
          tid = res.tid
          channel = res.channel || ''
          utm_source = res.utm_source || ''
          utm_share = res.utm_share || ''
          utm_medium = res.utm_medium || ''
          utm_term = res.utm_term || ''
          utm_content = res.utm_content || ''
          utm_campaign = res.utm_campaign || ''
          utm_search_keyword = res.utm_search_keyword || ''
          utm_traffic_source_type = res.utm_traffic_source_type || ''
        })
      } else {
        tid = paramArr[0]
        channel = paramArr[1]
      }
    } else {
      channel = options.channel || 'wx_xcx'
      tid = options.tid
      utm_source = options.utm_source || ''
      utm_share = options.utm_share || ''
      utm_medium = options.utm_medium || ''
      utm_term = options.utm_term || ''
      utm_content = options.utm_content || ''
      utm_campaign = options.utm_campaign || ''
      utm_search_keyword = options.utm_search_keyword || ''
      utm_traffic_source_type = options.utm_traffic_source_type || ''
    }

    let shareUploadParams = {
      utm_source: utm_source,
      utm_share: utm_share,
      utm_medium: utm_medium,
      utm_term: utm_term,
      utm_content: utm_content,
      utm_campaign: utm_campaign,
      utm_search_keyword: utm_search_keyword,
      utm_traffic_source_type: utm_traffic_source_type,
    }

    let query = wx.createSelectorQuery().in(this)
    query.select('#main').boundingClientRect((res) => {
      this.data.scrollActionY = res.height
    }).exec()

    // 获取登录用户UID
    wx.getStorage({
      key: 'userinfo',
      success: (res) => {
        this.data.uid = res.data.uid
      },
    })

    this.data.start = 0
    this.data.tid = tid
    this.data.channel = channel
    this.data.entrenceTime = dateFormat('yyyy-MM-dd hh:mm:ss:S')
    this.data.shareUtmTerm = utm_term
    this.data.shareUtmContent = utm_content
    this.data.shareUtmSearchKeyword = utm_search_keyword
    this.data.shareUtmTrafficSourceType = utm_traffic_source_type

    // 请求专题数据
    this.getTopicData(tid, this.data.start, channel)

    // TODO url改为配置
    this.setData({
      supportLaunchApp: app.data.supportLaunchApp,
      topicUrl: encodeURIComponent('https://m.ofashion.com.cn/topic/' + tid + '?utm_source=' + utm_source + '&utm_share=' + utm_share + '&utm_medium=' + utm_medium + '&utm_campaign=' + utm_campaign + '&utm_term=' + utm_term + '&utm_content=' + utm_content + '&utm_search_keyword=' + utm_search_keyword + '&utm_traffic_source_type=' + utm_traffic_source_type),
    })
    
    // 埋点上报
    this.shareUpload(shareUploadParams)

    let uploadParam = {
      cur_page_id: 'OFGoodsTopicWebViewController',
      cur_page_entrance_time: dateFormat('yyyy-MM-dd hh:mm:ss:S'),
      cur_page_entrence_type: 1,
      cur_page_resource_id: options.tid,
      ref_page_id: options.ref_page_id || null,
      opt_resource_area: 20,
      opt_resource_area_index: options.opt_resource_area_index || null,
      opt_resource_type: options.opt_resource_type || null,
      opt_resource_id: options.opt_resource_id || null,
      ref_page_resource_id: options.ref_page_resource_id || null,
      ref_opt_resource_area: options.ref_opt_resource_area || null, 
      ref_opt_resource_id: options.ref_opt_resource_id || null,
      ref_opt_resource_type: options.ref_opt_resource_type || null,
      ref_opt_protocol: options.ref_opt_protocol || null,
      ref_write_sever_timestamp: options.ref_write_sever_timestamp || null,
      log_type: options.log_type || null,
    }

    logUpload.handleUpload(uploadParam)
  },

  onPageScroll: function (res) {
    if (this.data.isShowFloorAll) {
      this.setData({
        isShowFloorAll: false
      })
    }

    let diffY = this.data.scrollActionY - res.scrollTop

    if (diffY < 0) {
      wx.createSelectorQuery().selectAll('.goods-select').boundingClientRect((rects) => {
        rects.forEach((rect, index) => {
          if (!this.data.scrollFlag[index]) {
            let scrollParam = {
              impr_page_id: 'OFGoodsTopicWebViewController',
              impr_resource_id: rect.id,
              impr_resource_type: 5,
              impr_time: dateFormat('yyyy-MM-dd hh:mm:ss:S'),
              impr_resource_info: rect.dataset.info,
              log_type: 3,
            }
            // log_type: 3 类型（展示日志）暂停上报
            // logUpload.handleUpload(scrollParam)
            this.data.scrollFlag[index] = true
          }
        })
      }).exec()
    }

    this.data.scrollActionY = res.scrollTop

    if (this.data.activeFloor !== '') {
      // 导航菜单是否粘贴顶部
      if (res.scrollTop - this.data.stickyTop > 0) {
        if (!this.data.isStickyFloor) {
          this.setData({
            isStickyFloor: true
          })
        }
        // console.log(this.data.navList)
        for (let i = 1; i < this.data.navList.length; i++) {
          if (res.scrollTop < this.data.navList[i].top - 58) {
            if (this.data.activeFloor !== this.data.navList[i - 1].id) {
              let menuScrollLeft = 0

              if (i < 2) {
                menuScrollLeft = 0
              } else {
                menuScrollLeft = this.data.menuWidth * (i - 3)
              }

              this.setData({
                activeFloor: this.data.navList[i - 1].id,
                menuScrollLeft
              })

              return
            }

            return
          }
        }

        if (this.data.navList.length && this.data.activeFloor !== this.data.navList[this.data.navList.length - 1].id) {
          this.setData({
            activeFloor: this.data.navList[this.data.navList.length - 1].id,
            menuScrollLeft: this.data.menuWidth * (this.data.navList.length - 3)
          })
        }

        // 解决ios回弹时fiexd的scroll-view 消失问题
        if (this.data.allHeight < res.scrollTop) {
          if (this.data.isMenuScroll) {
            this.setData({
              isMenuScroll: false,
              menuScrollLeft: 0,
            })
          }
        } else {
          if (!this.data.isMenuScroll) {
            this.setData({
              isMenuScroll: true,
            }, () => {
              this.setData({
                menuScrollLeft: this.data.menuWidth * (this.data.navList.length - 3),
              })
            })
          }
        }
      } else {
        if (this.data.isStickyFloor) {
          this.setData({
            isStickyFloor: false
          })
        }

        if (this.data.navList.length && this.data.activeFloor !== this.data.navList[0].id) {
          this.setData({
            activeFloor: this.data.navList[0].id,
            menuScrollLeft: 0,
          })
        }
      }
    }
  },

  toGoodsDetail: function(e) {
    let index = e.currentTarget.dataset.index
    let gid = e.currentTarget.id
    let opt_resource_type = 5
    let opt_protocol = 'pages/goods/goodsDetail/goodsDetail'
    let opt_time = dateFormat('yyyy-MM-dd hh:mm:ss:S')
    let log_type = 1
    let url = '../../goods/goodsDetail/goodsDetail?gid=' + gid + '&channel=' + this.data.channel + '&ref_page_id=OFGoodsTopicWebViewController' + '&ref_page_resource_id=' + this.data.tid + '&ref_opt_resource_id=' + gid + '&ref_opt_resource_type=5' + '&ref_opt_protocol=pages/topic/topicDetail/topicDetail&opt_resource_id=' + gid + '&opt_resource_type=' + opt_resource_type + '&opt_protocol=' + opt_protocol + '&opt_time=' + opt_time + '&log_type=' + log_type + '&ref_write_sever_timestamp=' + this.data.entrenceTime + 'opt_resource_area_index=' + index

    wx.navigateTo({
      url: url,
    })
  },

  onShareAppMessage: function () {
    let tid = this.data.tid
    let utm_share = ''

    if (this.data.uid == '') {
      utm_share = constants.SOURCE + '_' + Uuid.get()
    } else {
      utm_share = constants.SOURCE + '_' + this.data.uid
    }

    return {
        title: this.data.shareTitle,
        desc: this.data.shareDetail,
        path: '/pages/topic/topicDetail/topicDetail?tid=' + tid + '&channel=wx_xcx&utm_source=9_1&utm_share=' + utm_share + '&utm_medium=OFGoodsTopicWebViewController&utm_campaign=' + this.data.shareCampaign + '&utm_term=' + this.data.shareUtmTerm + '&utm_content=' + this.data.shareUtmContent + '&utm_search_keyword=' + this.data.shareUtmSearchKeyword + '&utm_traffic_source_type=' + this.data.shareUtmTrafficSourceType,
        imageUrl: this.data.shareImage,
    }
  },

  // 分享埋点数据上报
  shareUpload: function (params) {
    app.request({
      url: requestApi.shareUploadLogUrl,
      method: 'POST',
      login: false,
      data: {
        utm_source: params.utm_source,
        utm_share: params.utm_share,
        utm_medium: params.utm_medium,
        utm_term: params.utm_term,
        utm_content: params.utm_content,
        utm_campaign: params.utm_campaign,
        utm_search_keyword: params.utm_search_keyword,
        utm_traffic_source_type: params.utm_traffic_source_type,
      },
    }, (data) => {
      // console.log(data)
    }, (error) => {
      console.log(error)
    })
  },

  launchAppError(e) {
    if (e.detail.errMsg) {
      wx.showModal({
        title: '提示',
        content: app.data.launchAppFailTips,
        success: function (res) {
        }
      })
    }
  },

  scrolltolower: function (e) {
    this.data.start = this.data.start + this.data.count
    this.getTopicData(this.data.tid, this.data.start, this.data.channel)
  },

  setLivePara: function (e) {
    if (e.currentTarget.dataset.para) {
      this.setData({
        dialogHidden: false,
        protocol: e.currentTarget.dataset.para,
      })

      this.data.currentLiveInfo = e.currentTarget.dataset.currentLive
    }
  },

  closeDialog: function () {
    this.setData({
      dialogHidden: true
    })
  },

  // 订阅
  subscribeLive: function (e) {
    const liveData = this.data.topicData.detail_floor
    const liveId = e.currentTarget.dataset.liveid
    let liveProp, remind

    liveData.forEach((item, index) => {
      item.detail_list.forEach((item2, index2) => {
        if (item2.style_type == 32) {
          item2.item_list.forEach((item3, index3) => {
            if (item3.live_info.live_id == liveId) {
              liveProp = `topicData.detail_floor[${index}].detail_list[${index2}].item_list[${index3}].live_info.remind_me`
              remind = item3.live_info.remind_me
            }
          })
        }
      })
    })

    app.request({
      url: requestApi.subscribeLiveUrl,
      login: false,
      data: {
        live_id: liveId,
        type: Number(!remind),
      },
    }, (oridata) => {
      this.setData({
        [liveProp]: !remind,
        toastHidden: false,
        toastMsg: oridata.original.msg
      })

      setTimeout(() => {
        this.setData({
          toastHidden: true,
          toastMsg: '',
        })
      }, 1500)
    })
  },

  getTopicData: function (tid, start, channel) {
    if (this.data.noData) return false
    app.request({
      url: requestApi.topicDetailUrl,
      login: false,
      data: {
        tid: tid,
        channel: channel
      },
    }, (oridata) => {
      let data = oridata.original.data
      let noData = false
      let topicData = data
      let shareTitle = topicData.title
      let shareDetail = topicData.description
      let shareImage = ''
      let currentRecommend = this.data.recommendData
      let recommendTitle = ''
      let newRecommend = []
      let recommendData = []
      let that = this

      // Gucci活动结束处理：自动跳转到首页
      if (oridata.original.data.is_brand_activity == 1) {
        wx.switchTab({
          url: '../../index/index?channel=' + channel,
        })

        return true
      }

      wx.setNavigationBarTitle({
        title: topicData.title
      })

      if (data.cover_image.path) {
        topicData.cover_image.new_path = formatImage.cdnImage(topicData.cover_image.path, formatImage.THUMBNAIL_L)
        shareImage = topicData.cover_image.new_path
      }

      if (data.corner_mark.path) {
        topicData.corner_mark.new_path = formatImage.cdnImage(topicData.corner_mark.path, formatImage.THUMBNAIL_L)
      }

      if (data.description) {
        data.description = data.description.replace(/\<br\>/g, '\r\n')
      }

      if (topicData.detail_floor && topicData.detail_floor.length) {
        let topicArr = []

        topicData.detail_floor.forEach((floor, index) => {
          for (let i = 0, len = floor.detail_list.length; i < len; i++) {
            const detailList = floor.detail_list[i]

            for (let j = 0, jLen = detailList.item_list.length; j < jLen; j++) {
              const itemList = detailList.item_list[j]

              if (itemList.content && itemList.content.activity_image && itemList.content.activity_image.path){
                itemList.content.activity_image.new_path = formatImage.cdnImage(itemList.content.activity_image.path, formatImage.THUMBNAIL_M)
              }
            }

            if (detailList.style_type == 0) {
              for (let j = 0, jLen = detailList.item_list.length; j < jLen; j++) {
                const itemList = detailList.item_list[j]

                itemList.image.new_path = formatImage.cdnImage(itemList.image.path, formatImage.THUMBNAIL_M)
              }
            }

            if (detailList.style_type == 1) {
              detailList.item_list.forEach(function(item) {
                detailList.textIndex = index + 'floor' + i
                let content = item.content
                topicArr.push({
                  textIndex: index + 'floor' + i,
                  textItem: item.content,
                  floorIndex: index,
                })
              })
            }

            if (detailList.style_type == 32) {
              detailList.item_list.forEach(function(item) {
                if (item.live_info.cover_image && item.live_info.cover_image.path) {
                  item.live_info.cover_image.path_full = formatImage.cdnImage(item.live_info.cover_image.path, formatImage.THUMBNAIL_M)
                }
              })
            }

            if ([2, 3, 4, 5, 6, 7, 29, 30, 31].includes(Number(detailList.style_type))) {
              for (let j = 0, jLen = detailList.item_list.length; j < jLen; j++) {
                detailList.item_list[j].goods_info.product_cover_image.new_path = formatImage.cdnImage(detailList.item_list[j].goods_info.product_cover_image.path, formatImage.THUMBNAIL_M)
                detailList.item_list[j].goods_info.new_price_ref = detailList.item_list[j].goods_info.price_ref ? formatPrice(detailList.item_list[j].goods_info.price_ref / 100) : '';

                if(detailList.item_list[j].goods_info.tax_price) {
                    detailList.item_list[j].goods_info.new_goods_price = formatPrice(detailList.item_list[j].goods_info.tax_price / 100);
                } else {
                    detailList.item_list[j].goods_info.new_goods_price = detailList.item_list[j].goods_info.goods_price ? formatPrice(detailList.item_list[j].goods_info.goods_price / 100) : '';
                }

                detailList.item_list[j].goods_info.new_original_price = detailList.item_list[j].goods_info.original_price ? formatPrice(detailList.item_list[j].goods_info.original_price / 100 * 1) : ''
              }
            }

            if ([8, 9, 10, 11, 12, 13].includes(Number(detailList.style_type))) {
              for (let m = 0, mLen = detailList.item_list.length; m < mLen; m++) {
                detailList.item_list[m].comment_info.comment_image_list[0].new_path = formatImage.cdnImage(detailList.item_list[m].comment_info.comment_image_list[0].path, formatImage.THUMBNAIL_S)
              }
            }

            if ([14, 15].includes(Number(detailList.style_type))) {
              detailList.item_list.forEach(function(item) {
                if (item.seller_info && item.seller_info.avatar_image_uri) {
                  if (item.seller_info.avatar_image_uri.indexOf('http') != -1) {
                    item.seller_info.new_avatar_image_uri = item.seller_info.avatar_image_uri
                  } else {
                    item.seller_info.new_avatar_image_uri = item.seller_info.avatar_image_uri && item.seller_info.avatar_image_uri ? formatImage.cdnImage(item.seller_info.avatar_image_uri) : ''
                  }
                }
              })
            }

            if (detailList.style_type == 16) {
              for (let p = 0, pLen = detailList.item_list.length; p < pLen; p++) {
                detailList.item_list[p].tag_info.tag_img.new_path = detailList.item_list[p].tag_info.tag_img.path ? formatImage.cdnImage(detailList.item_list[p].tag_info.tag_img.path, formatImage.THUMBNAIL_XS) : ''
              }
            }

            if (detailList.style_type == 18) {
              for (let p = 0, pLen = detailList.item_list.length; p < pLen; p++) {
                let videoSrc = detailList.item_list[p].content ? formatImage.cdnVideo(detailList.item_list[p].content) : ''
                detailList.item_list[p].videoPath = videoSrc
                detailList.item_list[p].posterPath = videoSrc + '?x-oss-process=video/snapshot,t_0,f_jpg,m_fast'
              }
            }

            if (detailList.item_list && detailList.item_list.length) {
              let keywords = ''
              let brand_id = null
              let goods_type_id = null
              let gender_id = null
              let goods_prices = null

              for (let v = 0, vLen = detailList.item_list.length; v < vLen; v++) {
                if (detailList.item_list[v].data_type == 8) {
                  recommendTitle = detailList.item_list[v].content.title
                  keywords = detailList.item_list[v].content.keywords || ''

                  if (detailList.item_list[v].content.brand_limit) {
                    brand_id = this.jsonToString(detailList.item_list[v].content.brand_limit, ',')
                  }

                  if (detailList.item_list[v].content.goods_type_limit) {
                    goods_type_id = detailList.item_list[v].content.goods_type_limit.id
                  }

                  if (detailList.item_list[v].content.gender_id) {
                    gender_id = detailList.item_list[v].content.gender_id
                  }

                  if (detailList.item_list[v].content.tag_limit) {
                    keywords = keywords + this.jsonToString(detailList.item_list[v].content.tag_limit, ' ')
                  }

                  if (detailList.item_list[v].content.price_min || detailList.item_list[v].content.price_max) {
                    goods_prices = (detailList.item_list[v].content.price_min || '') + ':' + (detailList.item_list[v].content.price_max || '')
                  }

                  // 请求推荐商品数据
                  app.request({
                    url: requestApi.topicRecommendUrl,
                    login: false,
                    data: {
                      start: start,
                      count: this.data.count,
                      keywords: keywords,
                      brand_id: brand_id,
                      goods_type_id: goods_type_id,
                      gender_id: gender_id,
                      goods_prices: goods_prices,
                    },
                  }, (recData) => {
                    if (recData.original.goods && recData.original.goods.length) {
                      for (let i = 0, rLen = recData.original.goods.length; i < rLen; i++) {
                        recData.original.goods[i].product_cover_image.new_path = formatImage.cdnImage(recData.original.goods[i].product_cover_image.path, formatImage.THUMBNAIL_S)
                        recData.original.goods[i].new_goods_price = formatPrice(recData.original.goods[i].goods_price / 100)
                        recData.original.goods[i].new_original_price = recData.original.goods[i].original_price ? formatPrice(recData.original.goods[i].original_price / 100) : ''
                      }
                    }

                    newRecommend = recData.original.goods || []
                    recommendData = currentRecommend.concat(newRecommend)

                    if ((recData.original.goods && recData.original.goods < this.data.count) || !recData.original.goods) {
                      noData = true
                    }

                    this.setData({
                      noData: noData,
                      recommendTitle: recommendTitle,
                      recommendData: recommendData,
                    })
                  }, (error) => {
                    wx.showModal({
                      title: '提示',
                      showCancel: false,
                      content: error,
                    })
                  })
                }
              }
            }
          }
        })

        for (let i = 0; i < topicArr.length; i++) {
          WxParse.wxParse(topicArr[i].textIndex, 'html', topicArr[i].textItem, that);
          if (i === topicArr.length - 1) {
            WxParse.wxParseTemArray("topicArr", `${topicArr[i].floorIndex}floor`, topicArr, that)
          }
        }
      }

      wx.hideLoading()

      this.data.shareTitle = shareTitle
      this.data.shareDetail = shareDetail
      this.data.shareImage = shareImage
      this.data.shareCampaign = topicData.utm_campaign || ''

      this.setData({
        activeFloor: topicData.detail_floor[0].id ? topicData.detail_floor[0].id : '',
        topicData: topicData,
      }, () => {
        setTimeout(() => {
          wx.createSelectorQuery()
          .selectAll('#getHeight')
          .boundingClientRect(function(rect) {
						if (rect && rect.length) {
							that.data.allHeight = rect[rect.length - 1].bottom - wx.getSystemInfoSync().windowHeight
						}
          })
          .exec()

          for (let i = 0; i < topicData.detail_floor.length; i++) {
            if (this.data.activeFloor !== '') {
              let query = wx.createSelectorQuery().in(this)
              
              query
                .select(`#floor${topicData.detail_floor[i].id}`)
                .boundingClientRect(function(rect) {
                  that.data.navList.push({
                    id: topicData.detail_floor[i].id,
                    top: rect.top
                  })
                  console.log(that.data.navList)
                })
                .exec();
    
              // 如果楼层可以滚动，计算menu的宽度
              if (i === 4) {
                let query = wx.createSelectorQuery().in(this)
              
                query
                  .select(`.menu-item`)
                  .boundingClientRect(function(rect) {
                    that.data.menuWidth = rect.width
                  })
                  .exec();
              }
            }
          }
        }, 300);
      })

      wx.createSelectorQuery()
      .select(`.menu-sticky`)
      .boundingClientRect(function(rect) {
        if (rect) {
          that.data.stickyTop = rect.top
        }
      })
      .exec();
    }, (error) => {
      wx.showModal({
        title: '提示',
        showCancel: false,
        content: error,
      })
    })
  },

  jsonToString(jsonParam, separator) {
    let arr = [];

    for(let i = 0, len = jsonParam.length; i < len; i++) {
      arr.push(jsonParam[i].id);
    }

    let string = arr.join(separator);
    return string;
  },

  activeTap (e) {
    let activeID = e.currentTarget.dataset.id

    wx.navigateTo({
      url: '../../reservation/reservation?activity_id=' + activeID,
    })
  },

  sellerTap: function (e) {
    if (!app.toLogin()) {
      wx.hideLoading()

      return false
    }

    let seller_uid = e.currentTarget.dataset.id

    wx.navigateTo({
      url: '../../store/store?seller_uid=' + seller_uid,
    })
  },

  showFloorAll: function() {
    this.setData({
      isShowFloorAll: !this.data.isShowFloorAll,
    })
  },

  scrollToFloor: function(e) {
    if (this.data.isShowFloorAll) {
      this.setData({
        isShowFloorAll: false
      })
    }

    // 点击楼层肯定会吸顶
    if (!this.data.isStickyFloor) {
      this.setData({
        isStickyFloor: true
      })
    }

    let id = e.currentTarget.dataset.id
    let that = this

    if (id === this.data.activeFloor) return

    wx.createSelectorQuery()
      .select(`#floor${id}`)
      .boundingClientRect(function(rect) {
        console.log(`#floor${id}`, Math.floor(rect.top) + that.data.scrollActionY - 47)
        wx.pageScrollTo({
          scrollTop: Math.floor(rect.top) + that.data.scrollActionY - 47,
          duration: 0,
        });
      })
      .exec();
  }
})
